home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / php / PEAR / Log / observer.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  4.0 KB  |  130 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/observer.php,v 1.18 2006/04/25 06:02:23 jon Exp $
  4.  * $Horde: horde/lib/Log/observer.php,v 1.5 2000/06/28 21:36:13 jon Exp $
  5.  *
  6.  * @version $Revision: 1.18 $
  7.  * @package Log
  8.  */
  9.  
  10. /**
  11.  * The Log_observer:: class implements the Observer end of a Subject-Observer
  12.  * pattern for watching log activity and taking actions on exceptional events.
  13.  *
  14.  * @author  Chuck Hagenbuch <chuck@horde.org>
  15.  * @since   Horde 1.3
  16.  * @since   Log 1.0
  17.  * @package Log
  18.  *
  19.  * @example observer_mail.php   An example Log_observer implementation.
  20.  */
  21. class Log_observer
  22. {
  23.     /**
  24.      * Instance-specific unique identification number.
  25.      *
  26.      * @var integer
  27.      * @access private
  28.      */
  29.     var $_id = 0;
  30.  
  31.     /**
  32.      * The minimum priority level of message that we want to hear about.
  33.      * PEAR_LOG_EMERG is the highest priority, so we will only hear messages
  34.      * with an integer priority value less than or equal to ours.  It defaults
  35.      * to PEAR_LOG_INFO, which listens to everything except PEAR_LOG_DEBUG.
  36.      *
  37.      * @var string
  38.      * @access private
  39.      */
  40.     var $_priority = PEAR_LOG_INFO;
  41.  
  42.     /**
  43.      * Creates a new basic Log_observer instance.
  44.      *
  45.      * @param integer   $priority   The highest priority at which to receive
  46.      *                              log event notifications.
  47.      *
  48.      * @access public
  49.      */
  50.     function Log_observer($priority = PEAR_LOG_INFO)
  51.     {
  52.         $this->_id = md5(microtime());
  53.         $this->_priority = $priority;
  54.     }
  55.  
  56.     /**
  57.      * Attempts to return a new concrete Log_observer instance of the requested
  58.      * type.
  59.      *
  60.      * @param string    $type       The type of concreate Log_observer subclass
  61.      *                              to return.
  62.      * @param integer   $priority   The highest priority at which to receive
  63.      *                              log event notifications.
  64.      * @param array     $conf       Optional associative array of additional
  65.      *                              configuration values.
  66.      *
  67.      * @return object               The newly created concrete Log_observer
  68.      *                              instance, or null on an error.
  69.      */
  70.     function &factory($type, $priority = PEAR_LOG_INFO, $conf = array())
  71.     {
  72.         $type = strtolower($type);
  73.         $class = 'Log_observer_' . $type;
  74.  
  75.         /*
  76.          * If the desired class already exists (because the caller has supplied
  77.          * it from some custom location), simply instantiate and return a new
  78.          * instance.
  79.          */
  80.         if (class_exists($class)) {
  81.             $object = &new $class($priority, $conf);
  82.             return $object;
  83.         }
  84.  
  85.         /* Support both the new-style and old-style file naming conventions. */
  86.         $newstyle = true;
  87.         $classfile = dirname(__FILE__) . '/observer_' . $type . '.php';
  88.  
  89.         if (!file_exists($classfile)) {
  90.             $classfile = 'Log/' . $type . '.php';
  91.             $newstyle = false;
  92.         }
  93.  
  94.         /*
  95.          * Attempt to include our version of the named class, but don't treat
  96.          * a failure as fatal.  The caller may have already included their own
  97.          * version of the named class.
  98.          */
  99.         @include_once $classfile;
  100.  
  101.         /* If the class exists, return a new instance of it. */
  102.         if (class_exists($class)) {
  103.             /* Support both new-style and old-style construction. */
  104.             if ($newstyle) {
  105.                 $object = &new $class($priority, $conf);
  106.             } else {
  107.                 $object = &new $class($priority);
  108.             }
  109.             return $object;
  110.         }
  111.  
  112.         $null = null;
  113.         return $null;
  114.     }
  115.  
  116.     /**
  117.      * This is a stub method to make sure that Log_Observer classes do
  118.      * something when they are notified of a message.  The default behavior
  119.      * is to just print the message, which is obviously not desireable in
  120.      * practically any situation - which is why you need to override this
  121.      * method. :)
  122.      *
  123.      * @param array     $event      A hash describing the log event.
  124.      */
  125.     function notify($event)
  126.     {
  127.         print_r($event);
  128.     }
  129. }
  130.